<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1 style="display: inline-block" id="title">盘点损益表</h1>
    <button onclick="javascript:window.history.back();" type="button" class="btn btn-success"
            style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
        <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
           class="glyphicon glyphicon-share-alt"></i><span
            style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
    </button>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="padding: 5px 0px 0px 0px;margin: 0">
                                    <input name="cdlCpnId" th:value="${checkPlanModel.cpnId}" type="hidden"
                                           class="form-control text"/>
                                    <label class="control-label" style="text-align: right">
                                        区位
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlPosition" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入区位"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding: 10px 0px 0px 0px;margin: 0">
                                    <label class="control-label" style="text-align: right">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlProCode" type="text" class="form-control text"
                                               placeholder="请输入项目编号"/>
                                    </label>

                                </div>
                                <div class="form-group" style="padding: 10px 0px 0px 0px;margin: 0">
                                    <label class="control-label" style="text-align: right">
                                        项目文本
                                    </label>
                                    <label class="control-label">
                                        <input name="cdlProName" type="text" class="form-control text"
                                               placeholder="请输入项目名称"/>
                                    </label>

                                </div>
                                <div class="form-group" style="padding: 5px 0px 0px 0px;margin: 0">
                                    <label class="control-label" style="text-align: right">
                                        损益状态
                                    </label>
                                    <label class="control-label">
                                        <select name="cdlCheckStatus" class="form-control select">
                                            <option value="" selected>全部</option>
                                            <option value="1">盘盈</option>
                                            <option value="2">盘亏</option>
                                        </select>
                                    </label>
                                </div>

                                <!--<div class="form-group" style="padding: 5px 0px 0px 0px;margin: 0">
                                    <label class="control-label" style="text-align: right">
                                        申请状态
                                    </label>
                                    <label class="control-label">
                                        <select name="ajaItyStatus" id="ajaItyStatus" class="form-control select">
                                            <option value="">全部</option>
                                            <option value="1" selected>未提交</option>
                                            <option value="2">已提交</option>
                                            <option value="2">已通过</option>
                                        </select>
                                    </label>
                                </div>-->
                                <div class="form-group pull-right"
                                     style="padding-top: 10px;margin: 0px 0px 0px 0px;text-align: right">
                                    <button type="button" class="btn btn-vk" id="btn-search"
                                            style="color: white">搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <div class="col-md-12">
                        <h4>选中行损益汇总</h4>
                        <hr>
                        <table id="pal-table" class="table table-bordered " width="100%">

                        </table>
                    </div>
                    <div class="col-md-12">
                        <h4>库存调整申请</h4>
                        <hr>
                        <div class="col-md-11" style="text-align: right;">
                            <button shiro:hasPermission="purinv:purchecksub:edit" id="btn-submit"
                                    class="btn btn-warning">提交
                            </button>
                        </div>
                        <table id="bootstrap-table" class="table table-bordered " width="100%">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;

    /**
     * 有权看钱没权看星
     * */
    function displayMoney(value) {
        if (hasP('purinv:amount:view')) {
            return value;
        } else {
            return '***';
        }
    }

    /**
     *@FunctionName: loadCheckProgressTable
     *@Description: 选中行损益汇总
     *@Author: 徐一贺
     *@CreateDate: 2020/4/29 15:47
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function loadCheckProgressTable(data) {
        var ajaIds = "";
        for (var i = 0; i < data.length; i++) {
            ajaIds += +data[i].ajaId + ",";
        }
        ajaIds = ajaIds.substring(0, ajaIds.length - 1);
        $.post(ctx + "half/halInvManage/inventoryCheck/pal/sumList",
            {
                ajaIds: ajaIds
            },
            function (result) {
                $("#pal-table").bootstrapTable('destroy');
                js.table.init({
                    id: 'pal-table',
                    data: result.data.rows,
                    showColumns: true,
                    pagination: false,
                    showExport: false,
                    // pageSize: 300,
                    striped: false,
                    columns: [
                        {
                            title: '盘盈数量', field: 'profitCount', cellStyle: function (value, row, index) {
                                return {css: {"color": "green"}}
                            }
                        },
                        {
                            title: '盘亏数量', field: 'lossCount', cellStyle: function (value, row, index) {
                                return {css: {"color": "red", "font-weight": "900"}}
                            }
                        },
                        {
                            title: '盘盈金额', field: 'profitAmount', cellStyle: function (value, row, index) {
                                return {css: {"color": "green"}}
                            }
                        },
                        {
                            title: '盘亏金额', field: 'lossAmount', cellStyle: function (value, row, index) {
                                return {css: {"color": "red", "font-weight": "900"}}
                            }
                        },
                        {
                            title: '金额差值', field: 'differenceValueAmount', cellStyle: function (value, row, index) {
                                if (value >= 0) {
                                    return {css: {"color": "green"}}
                                } else {
                                    return {css: {"color": "red", "font-weight": "900"}}
                                }
                            }
                        },
                    ]
                })
                js.hot.loadData(result.data.rows);
                js.modal.success();
            }, 'json');
    }

    $(function () {
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "half/halInvManage/inventoryCheck/pal/list",
            showColumns: true,
            pagination: false,
            showExport: false,
            // pageSize: 300,
            striped: false,
            uniqueId: "ajaId",
            onLoadSuccess: function (data) {
                $('#bootstrap-table thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#bootstrap-table tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                loadCheckProgressTable(data.rows);
            },
            columns: [
                {
                    title: '序号', field: 'ajaId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '区位', field: 'cdlPosition'},
                {title: '物料描述', field: 'cdlMatName'},
                {title: 'SAP物料编码', field: 'cdlMatCode'},
                {title: '项目号', field: 'cdlProCode'},
                {title: '项目文本', field: 'cdlProName'},
                {title: '盘盈/盘损数量', field: 'cdlNum'},
                {
                    title: '数量损溢差', field: 'cdlPalVal', cellStyle: function (value, row, index) {
                        if (row.cdlCheckStatus == 2) {
                            return {css: {"color": "red", "font-weight": "900"}}
                        } else if (row.cdlCheckStatus == 1) {
                            return {css: {"color": "green"}}
                        } else {
                            return {css: {"color": "#333333"}}
                        }
                    }
                },
                {
                    title: '单价', field: 'cdlPrice', formatter: function (value, row, index) {
                        return displayMoney(value);
                    }
                },
                {title: '单位', field: 'cdlUnit'},
                {
                    title: '金额损溢差', field: 'cdlPalAmount', cellStyle: function (value, row, index) {
                        if (row.cdlCheckStatus == 2) {
                            return {css: {"color": "red", "font-weight": "900"}}
                        } else if (row.cdlCheckStatus == 1) {
                            return {css: {"color": "green"}}
                        } else {
                            return {css: {"color": "#333333"}}
                        }
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            //已提交隐藏批量提交按钮
            if ($("#ajaItyStatus").val() == 2) {
                $("#btn-submit").hide();
            } else {
                $("#btn-submit").show();
            }
            js.table.search(table);
        });
        /**提交*/
        $("#btn-submit").on('click', function () {
            js.modal.confirm("尊敬的用户，您确认要提交盘点损益表吗？", function () {
                var data = $('#bootstrap-table').bootstrapTable('getData');

                var ajaIds = "";
                for (var i = 0; i < data.length; i++) {
                    ajaIds += +data[i].ajaId + ",";
                }

                ajaIds = ajaIds.substring(0, ajaIds.length - 1);
                $.post(ctx + "half/halInvManage/inventoryCheck/pal/submit",
                    {
                        cdlCpnId: $("#queryForm [name='cdlCpnId']").val(),
                        ajaIds: ajaIds
                    },
                    function (result) {
                        if (result.type == 'SUCCESS') {
                            location.href = ctx + "half/halInvManage/inventoryCheck/page";
                        }
                    }, 'json');
            });
        });
    });
</script>
</body>
</html>
*